package com.github.pig.wxapi.controller;

import com.github.pig.wxapi.controller.request.WxRequest;
import com.qq.weixin.mp.aes.AesException;
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("callBack")
public class WxCallBackController {
    @Value("{token}")
    private String token;
    @Value("{appsecret}")
    private String encodingAesKey;
    @Value("{appID}")
    private String appId;
    @GetMapping("message")
    public Object message(WxRequest wxRequest) throws AesException {
        WXBizMsgCrypt pc=new WXBizMsgCrypt(token,encodingAesKey,appId);
        String result2 = pc.encryptMsg(token,wxRequest.getTimestamp(),wxRequest.getNonce());
        System.out.println("传入:"+wxRequest.getSignature());
        System.out.println("解密后明文: " + result2);
        return wxRequest.getEchostr();
    }
}
